# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : code03.py
# @Time     : 2024/4/6 18:30
# @Author   : Robot-Zsj
"""
description:

input
2 2
1 0
1 1

output
3
"""


# dfs
def main():
    n, m = map(int, input().split())
    matrix = [list(map(int, input().split())) for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(m):
            ans = max(ans, dfs(i, j, 0, n, m, matrix))
    return ans


def dfs(i, j, count, n, m, matrix):
    if i < 0 or i >= n or j < 0 or j >= m or matrix[i][j] == 0:
        return count
    count += 1
    matrix[i][j] = 0
    count = dfs(i - 1, j, count, n, m, matrix)
    count = dfs(i + 1, j, count, n, m, matrix)
    count = dfs(i, j - 1, count, n, m, matrix)
    count = dfs(i, j + 1, count, n, m, matrix)

    return count


print(main())
